package J11_2;
import java.util.*;



public class test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        char[][] chars = new char[n][n];
        in.nextLine(); // 清除换行符
        long startTime = System.currentTimeMillis();
        // 读取网格数据
        for (int i = 0; i < n; i++) {
            chars[i] = in.nextLine().toCharArray();
        }

        // 使用Set存储不同的图案
        Set<List<String>> patterns = new HashSet<>();

        // 遍历所有可能的M×M子区域
        for (int i = 0; i <= n - m; i++) {
            for (int j = 0; j <= n - m; j++) {
                // 提取当前M×M区域
                List<String> pattern = new ArrayList<>();
                for (int row = i; row < i + m; row++) {
                    StringBuilder sb = new StringBuilder();
                    for (int col = j; col < j + m; col++) {
                        sb.append(chars[row][col]);
                    }
                    pattern.add(sb.toString());
                }
                patterns.add(pattern);
            }
        }
        long endTime = System.currentTimeMillis();
        long executionTime = endTime - startTime;
        System.out.println("执行时间: " + executionTime + " 毫秒");
        System.out.println(patterns.size());
    }
}
